/*   1:    */ package org.jetbrains.jps.model.impl;
/*   2:    */ 
/*   3:    */

import com.intellij.openapi.util.Condition;
import com.intellij.util.SmartList;
import com.intellij.util.containers.FilteringIterator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.*;
import org.jetbrains.jps.model.ex.JpsElementBase;

import java.util.*;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */
/*  21:    */
/*  22:    */
/*  23:    */ 
/*  24:    */ public class JpsElementCollectionImpl<E extends JpsElement>
/*  25:    */   extends JpsElementBase<JpsElementCollectionImpl<E>>
/*  26:    */   implements JpsElementCollection<E>
/*  27:    */ {
/*  28:    */   private final List<E> a;
/*  29:    */   private final Map<E, E> b;
/*  30:    */   private final JpsElementChildRole<E> c;
/*  31:    */   
/*  32:    */   JpsElementCollectionImpl(JpsElementChildRole<E> paramJpsElementChildRole)
/*  33:    */   {
/*  34: 36 */     this.c = paramJpsElementChildRole;
/*  35: 37 */     this.a = new SmartList();
/*  36: 38 */     this.b = null;
/*  37:    */   }
/*  38:    */   
/*  39:    */   private JpsElementCollectionImpl(JpsElementCollectionImpl<E> paramJpsElementCollectionImpl)
/*  40:    */   {
/*  41: 42 */     this.c = paramJpsElementCollectionImpl.c;
/*  42: 43 */     this.a = new SmartList();
/*  43: 44 */     this.b = new HashMap();
/*  44: 45 */     for (JpsElement localJpsElement1 : paramJpsElementCollectionImpl.a)
/*  45:    */     {
/*  46: 47 */       JpsElement localJpsElement2 = localJpsElement1.getBulkModificationSupport().createCopy();
/*  47: 48 */       setParent(localJpsElement2, this);
/*  48: 49 */       this.a.add(localJpsElement2);
/*  49: 50 */       this.b.put(localJpsElement2, localJpsElement1);
/*  50:    */     }
/*  51:    */   }
/*  52:    */   
/*  53:    */   public List<E> getElements()
/*  54:    */   {
/*  55: 56 */     return this.a;
/*  56:    */   }
/*  57:    */   
/*  58:    */   public <X extends JpsTypedElement<P>, P extends JpsElement> Iterable<X> getElementsOfType(@NotNull JpsElementType<P> paramJpsElementType)
/*  59:    */   {
/*  60: 61 */     if (paramJpsElementType == null) {
/*  61: 61 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jps/model/impl/JpsElementCollectionImpl", "getElementsOfType" }));
/*  62:    */     }
/*  63: 61 */     return new JpsElementIterable(paramJpsElementType);
/*  64:    */   }
/*  65:    */   
/*  66:    */   @NotNull
/*  67:    */   public E addChild(@NotNull JpsElementCreator<E> paramJpsElementCreator)
/*  68:    */   {
/*  69: 67 */     if (paramJpsElementCreator == null) {
/*  70: 67 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jps/model/impl/JpsElementCollectionImpl", "addChild" }));
/*  71:    */     }
/*  72: 67 */     JpsElement tmp50_47 = addChild(paramJpsElementCreator.create());
/*  73: 67 */     if (tmp50_47 == null) {
/*  74: 67 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/jetbrains/jps/model/impl/JpsElementCollectionImpl", "addChild" }));
/*  75:    */     }
/*  76: 67 */     return tmp50_47;
/*  77:    */   }
/*  78:    */   
/*  79:    */   public <X extends E> X addChild(X paramX)
/*  80:    */   {
/*  81: 72 */     this.a.add(paramX);
/*  82: 73 */     setParent(paramX, this);
/*  83: 74 */     JpsEventDispatcher localJpsEventDispatcher = getEventDispatcher();
/*  84: 75 */     if (localJpsEventDispatcher != null) {
/*  85: 76 */       localJpsEventDispatcher.fireElementAdded(paramX, this.c);
/*  86:    */     }
/*  87: 78 */     return paramX;
/*  88:    */   }
/*  89:    */   
/*  90:    */   public void removeChild(@NotNull E paramE)
/*  91:    */   {
/*  92: 83 */     if (paramE == null) {
/*  93: 83 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jps/model/impl/JpsElementCollectionImpl", "removeChild" }));
/*  94:    */     }
/*  95: 83 */     boolean bool = this.a.remove(paramE);
/*  96: 84 */     if (bool)
/*  97:    */     {
/*  98: 85 */       JpsEventDispatcher localJpsEventDispatcher = getEventDispatcher();
/*  99: 86 */       if (localJpsEventDispatcher != null) {
/* 100: 87 */         localJpsEventDispatcher.fireElementRemoved(paramE, this.c);
/* 101:    */       }
/* 102: 89 */       setParent(paramE, null);
/* 103:    */     }
/* 104:    */   }
/* 105:    */   
/* 106:    */   public void removeAllChildren()
/* 107:    */   {
/* 108: 95 */     ArrayList localArrayList = new ArrayList(this.a);
/* 109: 96 */     for (JpsElement localJpsElement : localArrayList) {
/* 110: 97 */       removeChild(localJpsElement);
/* 111:    */     }
/* 112:    */   }
/* 113:    */   
/* 114:    */   @NotNull
/* 115:    */   public JpsElementCollectionImpl<E> createCopy()
/* 116:    */   {
/* 117:104 */     void tmp8_5 = new JpsElementCollectionImpl(this);
/* 118:104 */     if (tmp8_5 == null) {
/* 119:104 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/jetbrains/jps/model/impl/JpsElementCollectionImpl", "createCopy" }));
/* 120:    */     }
/* 121:104 */     return tmp8_5;
/* 122:    */   }
/* 123:    */   
/* 124:    */   public void applyChanges(@NotNull JpsElementCollectionImpl<E> paramJpsElementCollectionImpl)
/* 125:    */   {
/* 126:108 */     if (paramJpsElementCollectionImpl == null) {
/* 127:108 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jps/model/impl/JpsElementCollectionImpl", "applyChanges" }));
/* 128:    */     }
/* 129:108 */     LinkedHashSet localLinkedHashSet = new LinkedHashSet(this.a);
/* 130:109 */     ArrayList localArrayList = new ArrayList();
/* 131:110 */     Map localMap = paramJpsElementCollectionImpl.b;
/* 132:111 */     for (Iterator localIterator = paramJpsElementCollectionImpl.a.iterator(); localIterator.hasNext();)
/* 133:    */     {
/* 134:111 */       localJpsElement1 = (JpsElement)localIterator.next();
/* 135:112 */       Object localObject = localMap != null ? (JpsElement)localMap.get(localJpsElement1) : null;
/* 136:113 */       if (localObject != null)
/* 137:    */       {
/* 138:115 */         localObject.getBulkModificationSupport().applyChanges(localJpsElement1);
/* 139:116 */         localLinkedHashSet.remove(localObject);
/* 140:    */       }
/* 141:    */       else
/* 142:    */       {
/* 143:120 */         JpsElement localJpsElement2 = localJpsElement1.getBulkModificationSupport().createCopy();
/* 144:121 */         localArrayList.add(localJpsElement2);
/* 145:    */       }
/* 146:    */     }
/* 147:    */     JpsElement localJpsElement1;
/* 148:124 */     for (localIterator = localLinkedHashSet.iterator(); localIterator.hasNext();)
/* 149:    */     {
/* 150:124 */       localJpsElement1 = (JpsElement)localIterator.next();
/* 151:125 */       removeChild(localJpsElement1);
/* 152:    */     }
/* 153:127 */     for (localIterator = localArrayList.iterator(); localIterator.hasNext();)
/* 154:    */     {
/* 155:127 */       localJpsElement1 = (JpsElement)localIterator.next();
/* 156:128 */       addChild(localJpsElement1);
/* 157:    */     }
/* 158:    */   }
/* 159:    */   
/* 160:    */   private class JpsElementIterable<X extends JpsTypedElement<P>, P extends JpsElement>
/* 161:    */     implements Iterable<X>
/* 162:    */   {
/* 163:    */     private final JpsElementType<? extends JpsElement> a;
/* 164:    */     
/* 165:    */     public JpsElementIterable()
/* 166:    */     {
/* 167:    */       Object localObject;
/* 168:136 */       this.a = localObject;
/* 169:    */     }
/* 170:    */     
/* 171:    */     public Iterator<X> iterator()
/* 172:    */     {
/* 173:142 */       Iterator localIterator = JpsElementCollectionImpl.this.a.iterator();
/* 174:143 */       new FilteringIterator(localIterator, new Condition()
/* 175:    */       {
/* 176:    */         public boolean value(JpsTypedElement<?> paramAnonymousJpsTypedElement)
/* 177:    */         {
/* 178:146 */           return paramAnonymousJpsTypedElement.getType().equals(JpsElementCollectionImpl.JpsElementIterable.this.a);
/* 179:    */         }
/* 180:    */       });
/* 181:    */     }
/* 182:    */   }
/* 183:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.jps.model.impl.JpsElementCollectionImpl

 * JD-Core Version:    0.7.0.1

 */